package com.jieao.backend.controller.site;

import java.util.List;

import com.jieao.biz.domain.SiteFeedBack;
import com.jieao.biz.dto.SiteFeedBackDto;
import com.jieao.site.service.ISiteFeedBackService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jieao.common.annotation.Log;
import com.jieao.common.enums.BusinessType;
import com.jieao.common.core.controller.BaseController;
import com.jieao.common.core.domain.AjaxResult;
import com.jieao.common.utils.poi.ExcelUtil;
import com.jieao.common.core.page.TableDataInfo;

/**
 * 游客反馈Controller
 *
 * @author jieao
 * @date 2020-09-11
 */
@Controller
@RequestMapping("/site/feedBack")
public class SiteFeedBackController extends BaseController {
    private String prefix = "/backend/site/feedBack";

    @Autowired
    private ISiteFeedBackService siteFeedBackService;

    @RequiresPermissions("site:feedBack:view")
    @GetMapping()
    public String back() {
        return prefix + "/feedBack";
    }

    /**
     * 查询游客反馈列表
     */
    @RequiresPermissions("site:feedBack:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SiteFeedBackDto siteFeedBack) {
        startPage();
        List<SiteFeedBackDto> list = siteFeedBackService.selectSiteFeedBackList(siteFeedBack);
        return getDataTable(list);
    }

    /**
     * 导出游客反馈列表
     */
    @RequiresPermissions("site:feedBack:export")
    @Log(title = "游客反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SiteFeedBackDto siteFeedBack) {
        List<SiteFeedBackDto> list = siteFeedBackService.selectSiteFeedBackList(siteFeedBack);
        ExcelUtil<SiteFeedBackDto> util = new ExcelUtil<SiteFeedBackDto>(SiteFeedBackDto.class);
        return util.exportExcel(list, "feedBack");
    }

    /**
     * 新增游客反馈
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存游客反馈
     */
    @RequiresPermissions("site:feedBack:add")
    @Log(title = "游客反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SiteFeedBack siteFeedBack) {
        return toAjax(siteFeedBackService.insertSiteFeedBack(siteFeedBack));
    }

    /**
     * 修改游客反馈
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SiteFeedBack siteFeedBack = siteFeedBackService.selectSiteFeedBackById(id);
        mmap.put("siteFeedBack", siteFeedBack);
        return prefix + "/edit";
    }

    /**
     * 修改保存游客反馈
     */
    @RequiresPermissions("site:feedBack:edit")
    @Log(title = "游客反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SiteFeedBack back) {
        SiteFeedBack siteFeedBack = siteFeedBackService.selectSiteFeedBackById(back.getId());
        siteFeedBack.setIsRead(1);
        return toAjax(siteFeedBackService.updateSiteFeedBack(siteFeedBack));
    }

    /**
     * 删除游客反馈
     */
    @RequiresPermissions("site:feedBack:remove")
    @Log(title = "游客反馈", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(siteFeedBackService.deleteSiteFeedBackByIds(ids));
    }
}
